package Einkaufer;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

public class KonfigurationTable {
	
	 private KonfigurationTableModel ktm;
	 private Connection cn;
	 
	 public KonfigurationTable(Connection cn){
		
		 this.cn = cn;
		 
	 }
	
	
	
	
	 public void initKonfigurationTable(String selectedItem) throws SQLException{
				
		ktm = new KonfigurationTableModel();
		ArrayList<KonfigurationList> kfl;
		

        ResultSet rs;
        Statement st = (Statement) cn.createStatement();
        rs = st.executeQuery("SELECT * FROM konfiguration JOIN " +
                "vehiclepart ON konfiguration.vpid = vehiclepart.vpid " +
                "WHERE vehiclepart.name = '"+selectedItem+"'" );

        while (rs.next()){

            String kid = rs.getString("kid");
            String kind = rs.getString("kind");
            String delivery_time = rs.getString("delivery_time");
            String unit = rs.getString("unit");
            String slots_per_unit = rs.getString("slots_per_unit");
            
            kfl = new ArrayList<KonfigurationList>();
            
            kfl.add(new KonfigurationList(kid));
            kfl.add(new KonfigurationList(kind));
            kfl.add(new KonfigurationList(delivery_time));
            kfl.add(new KonfigurationList(unit));
            kfl.add(new KonfigurationList(slots_per_unit));
           
            ktm.setValueAt(kfl);
            
        }
       
	}


	public KonfigurationTableModel getKtm() {
		return ktm;
	}

}
